/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.sip.*;
import java.util.Properties;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class TestAppMain {
    private final static Log logger = LogFactory.getLog("TestAppMain");

    public static void main(String[] args) {
        System.out.println("Starting test application...");
        final SipFactory factory = SipFactory.getInstance();
        factory.setPathName("com.jnetx");
        final SipStack stack;
        final Properties props = readConfig();
        try {
            stack = SipFactory.getInstance().createSipStack(props);
        } catch (PeerUnavailableException e) {
            logger.error("Cannot create SIP stack!", e);
            System.exit(1);
            return;
        }
        final ListeningPoint lPoint;
        try {
            lPoint = stack.createListeningPoint(props.getProperty("com.jnetx.javax.sip.IP_ADDRESS"), 10000, "UDP");
        } catch (Exception e) {
            logger.error("Cannot create the listening point!", e);
            System.exit(1);
            return;
        }
        final SipProvider provider;
        try {
            provider = stack.createSipProvider(lPoint);
        } catch (ObjectInUseException e) {
            logger.error("Cannot get a SIP provider!", e);
            System.exit(1);
            return;
        }
//        stack.get
//        provider.sendRequest();
    }

    private static Properties readConfig() {
        final Properties props = new Properties();
        props.setProperty("javax.sip.STACK_NAME", "Deps SIP Stack v0.1");
        //Current IP address
        try {
            InetAddress local = InetAddress.getLocalHost();
            props.setProperty("com.jnetx.javax.sip.IP_ADDRESS", local.getHostAddress());
        } catch (UnknownHostException e) {
            logger.error("Cannot get the local host's IP address!", e);
        }
        return props;
    }
}
/*
 * $Log$
 */